//
//  ViewController.swift
//  CheckmeRing
//
//  Created by 董鹏 on 2022/1/26.
//

import UIKit

class ViewController: RViewController, ChartViewDelegate {
    
    var chartView1 = LineChartView()

    func chartScaled(_ chartView: ChartViewBase, scaleX: CGFloat, scaleY: CGFloat) {
        chartView1.zoomToCenter(scaleX: scaleX, scaleY: scaleY)
    }
    
    func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat) {
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let chartView = LineChartView()
        chartView.delegate = self
        chartView.frame = CGRect(x: 20, y: 20, width: kScreenWidth - 40, height: 300)
        self.view.addSubview(chartView)

        var dataEntries = [ChartDataEntry]()
        for i in 0..<100 {
            let y = arc4random() % 100
            let entry = ChartDataEntry(x: Double(i), y: Double(y))
            dataEntries.append(entry)
        }
        let chartDataSet = LineChartDataSet(entries: dataEntries, label: "图例1")
        let chartData = LineChartData(dataSets: [chartDataSet])
        chartView.data = chartData
        
        
        self.chartView1 = LineChartView()
        chartView1.frame = CGRect(x: 20, y: chartView.bottom + 20, width: kScreenWidth - 40, height: 300)
        self.view.addSubview(chartView1)
        chartView1.data = chartData
        
        
//        let document = PDFDocument(format: .a4)
//        // 文字
//        document.add(.headerCenter, text: "Create PDF documents easily.")
//        let generator = PDFGenerator(document: document)
//
//        // 线
//        let style = PDFLineStyle(type: .full, color: .darkGray, width: 0.5)
//        document.addLineSeparator(PDFContainer.contentLeft, style: style)
//
//        // 图像
//        let img = chartView.changeToImage(size: CGSize(width: kScreenWidth, height: 300))
//        let imageElement = PDFImage(image: img)
//        document.add(image: imageElement)
//
//        let url = try! generator.generateURL(filename: "Example.pdf")
//        print(url)
        
        
//        let A4paperSize = CGSize(width: 595, height: 842)
//        let pdf = SimplePDF(pageSize: A4paperSize)
//
//        pdf.addText("Hello World!")
//
//        let img = chartView.changeToImage(size: CGSize(width: kScreenWidth, height: 300))
//        pdf.addImage(img)
//        pdf.addImage(img)
//        pdf.addImage(img)
//        pdf.setContentAlignment(.right)
//        let pdfData = pdf.generatePDFdata()
//
//        // save as a local file
//        let path = URL(fileURLWithPath: "Users/dongpeng/Desktop/test.pdf")
//        try! pdfData.write(to: path, options: .atomic)
        
    }

}

